package com.qf.mybatisDynamicSqlDemo.until;

import cn.hutool.core.collection.CollUtil;
import com.qf.mybatisDynamicSqlDemo.entity.Book;

import java.util.ArrayList;
import java.util.List;

/**
 * 拆分list工具类
 *
 * @author 刘欣
 * @createTime 2022/12/22 22:47
 * @description
 */
public class SplitListUntil {
    public static List<List<Book>> splitList(List<Book> list) {
        List<List<Book>> books = new ArrayList<>();
        int start = 0;
        int end = 2000;
        boolean flag = true;
        while (flag) {
            if (end < list.size()) {
                List<Book> sub = CollUtil.sub(list, start, end);
                books.add(sub);
            } else {
                end = list.size();
                List<Book> sub = CollUtil.sub(list, start, end);
                books.add(sub);
                break;
            }
            start = end;
            end += 2000;
        }
        return books;
    }
}
